package com.quanyue.mechanics.complex.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.mechanics.complex.service.CaseService;
import com.quanyue.mechanics.domain.entity.Case;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.mybatis.mapper.page.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(tags = "成功案例")
@RestController
@RequestMapping("/api")
public class CaseController {
    @Autowired
    private CaseService caseService;

    @ApiOperation(value = "添加案例")
    @PostMapping(value = "/case", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Case> addCase(@RequestBody Case ca) {
        return ServiceResult.success(caseService.addCase(ca));
    }

    @ApiOperation(value = "修改案例")
    @PutMapping(value = "/case", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> updateCase(@RequestBody Case ca) {
        caseService.updateCase(ca);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除案例")
    @DeleteMapping(value = "/case", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> deleteCase(@RequestParam("id") Integer id) {
        caseService.deleteCase(id);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "案例列表")
    @PostMapping(value = "/case/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Page <Case>> findCase(@RequestBody PageRequest request) {
        return ServiceResult.success(caseService.findCase(request));
    }
}
